﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LitJson;
using UnityEngine;

public class MultBranchSerializor: LeafSerializor
{
    public override INodeData DeSerializeData(string json)
    {
        INodeData node = new MultiBranchNodeData();
        JsonData data = JsonMapper.ToObject(json);
        NodeDataDeSerialize(data, ref node);
        ((MultiBranchNodeData)node).ChildNodes = new List<NodeData>();
        if (data["ChildNodes"].IsArray)
        {
            JsonData temp;
            INodeDataSerializor Serializor;
            for (int i = 0; i < data["ChildNodes"].inst_array.Count; i++)
            {
                temp = data["ChildNodes"].inst_array[i];
                Serializor = BehaviorSystem.NodeDataSerilizors[temp["NodeType"].AsInt];
                NodeData nodeData = (NodeData)Serializor.DeSerializeData(temp.ToJson());
                ((MultiBranchNodeData)node).ChildNodes.Add(nodeData);
            }
        } 
        return node;
    }
}